﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellActionDialect_h
#define CellActionDialect_h

#include "CellPrerequisites.h"
#include "CellDialect.h"
#include "CellDialectFactory.h"

namespace cell
{
/** 动作执行方言。
 *
 * @author
 *		Jiangwei Xu
 */
class _CellExport ActionDialect : public Dialect
{
public:
	/**
	*/
	ActionDialect(const String& tracker);

	/**
	*/
	virtual ~ActionDialect(void);

public:
	/**
	*/
	bool translate(Primitive& primitive);

protected:
	/**
	*/
	void build(Primitive* primitive);

public:
	/** 设置动作名称。
	*/
	void setAction(const String& action);

	/** 返回动作名称。
	*/
	const String& getAction(void) const;

	/**
	*/
	void appendParam(const String& name, const char* value);
	/**
	*/
	void appendParam(const String& name, const String& value);
	/**
	*/
	void appendParam(const String& name, int value);
	/**
	*/
	void appendParam(const String& name, uint value);
	/**
	*/
	void appendParam(const String& name, long value);
	/**
	*/
	void appendParam(const String& name, ulong value);
	/**
	*/
	void appendParam(const String& name, bool value);

	/**
	*/
	String getParamAsString(const String& name);
	/**
	*/
	int getParamAsInt(const String& name);
	/**
	*/
	uint getParamAsUInt(const String& name);
	/**
	*/
	long getParamAsLong(const String& name);
	/**
	*/
	ulong getParamAsULong(const String& name);
	/**
	*/
	bool getParamAsBool(const String& name);

	/** 判断指定名称的参数是否存在。
	*/
	bool existParam(const String& name);

	/** 复制参数到指定目标。
	*/
	void copyParams(ActionDialect& target);

	/** 执行动作。
	*/
	void act(ActionDelegate* delegate);

private:
	typedef boost::unordered_map<String, String> Params;

	String mAction;
	Params mParams;
};


/** 动作方言工厂。
*/
class _CellExport ActionDialectFactory : public DialectFactory
{
public:
	/**
	*/
	ActionDialectFactory(void);

	/**
	*/
	virtual ~ActionDialectFactory(void);

public:
	/**
	*/
	Dialect* createInstance(const String& tracker);

	/**
	*/
	void destroyInstance(Dialect* instance);

protected:
	/// 内部方法用于初始化 Meta Data
	void initMetaData(void) const;

public:
	/// 
	static const String FACTORY_NAME;
};
} // end namespace cell

#endif // CellActionDialect_h
